package com.situ.mall.controller;

import com.situ.mall.pojo.Product;
import com.situ.mall.service.IProductService;
import com.situ.mall.util.JSONResult;
import com.situ.mall.util.LayUITableResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private IProductService productService;

    @RequestMapping("/getProductListPage")
    public String getProductListPage() {
        return "product_list";
    }

    // ?page=1&limit=10
    @RequestMapping("/selectByPage")
    @ResponseBody
    public LayUITableResult selectByPage(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10")Integer limit) {
        System.out.println("ProductController.selectByPage");
        return productService.selectByPage(page, limit);
    }

    @RequestMapping("/getProductInsertPage")
    public String getProductInsertPage() {
        return "product_insert";
    }

    @RequestMapping("/insert")
    @ResponseBody
    public JSONResult insert(Product product) {
        System.out.println("ProductController.insert");
        productService.insert(product);
        return JSONResult.ok("插入成功");
    }
}
